import Vue from 'vue'
import App from './App.vue'
import router from "./router"
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import store from './store'
import './api/mock'
import Cookie from 'js-cookie'
Vue.prototype.$bus=new Vue();
Vue.config.productionTip = false
Vue.use(ElementUI)
//添加全局前置路由守卫
router.beforeEach((to,from,next)=>{
const token=Cookie.get('token')
if(!token&&to.name!=='logain')
{
  next({name:'logain'})
}
if(token&&to.name=='logain')
{
  next({name:from.name})
}
else
{
  next();
}
})
new Vue({
  render: h => h(App),
  router,
  store,
  created(){
    store.commit('addmenu',router)
  }
}).$mount('#app')
